package com.DreamTeam.service;

import com.DreamTeam.factory.DaoFactory;
import com.DreamTeam.po.User;

public class SystemManagerService implements ISystemManagerService {

	@Override
	public boolean login(User user) {
		User temp = DaoFactory.getUserDaoImplInstance().queryUserByUserName(
				user.getUserName());
		if (temp != null)
			if (temp.getPassword().equals(user.getPassword())
					&& temp.getPermission() == user.getPermission())
				return true;
			else
				return false;
		else
			return false;
	}

	@Override
	public boolean register(User user) {
		User temp = DaoFactory.getUserDaoImplInstance().queryUserByUserName(
				user.getUserName());
		if (temp != null)
			return false;
		else
			return DaoFactory.getUserDaoImplInstance().doAdd(user);
	}

	@Override
	public boolean userModify(User user, String oldPassword) {
		User temp = DaoFactory.getUserDaoImplInstance().queryUserByUserName(
				user.getUserName());
		if (temp != null)
			if (temp.getPassword().equals(oldPassword))
				return DaoFactory.getUserDaoImplInstance().doUpdate(user);
			else
				return false;
		else
			return false;
	}

}
